#include <iostream>
#include <pthread.h>
#include <string>
#include <unistd.h>

std::string toHex(const pthread_t &tid)
{
    char ret[128] = {0};
    snprintf(ret, 128, "0x%lx", tid);
    return std::string(ret);
}
void *threadRun(void *atr)
{
    while (true)
    {
        sleep(1);
        std::cout << (char *)atr << " is running, the tid is " << toHex(pthread_self()) << std::endl;
    }
    return atr;
}
int main()
{
    // 1.创建线程：
    pthread_t tid;
    pthread_create(&tid, nullptr, threadRun, (void *)"thread-1");

    std::cout << "The new thread's tid is " << toHex(tid) << std::endl;

    // 2.等待：
    pthread_join(tid, nullptr);
    return 0;
}
